package com.zingrow.web.report.controller;

import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.Else;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.idaycrm.idaybase.utils.JsonUtils;
import com.zingrow.common.ReturnStandardDataFormat;
import com.zingrow.common.utils.EncodingUtils;
import com.zingrow.common.utils.OptClass;
import com.zingrow.common.utils.PageView;
import com.zingrow.web.base.CodeMsg;
import com.zingrow.web.base.controller.BaseController;
import com.zingrow.web.base.enums.Menu;
import com.zingrow.web.base.enums.Operation;
import com.zingrow.web.base.enums.OperationDeed;
import com.zingrow.web.base.enums.OperationModule;
import com.zingrow.web.customer.service.IGroupService;
import com.zingrow.web.report.base.Cycle;
import com.zingrow.web.report.model.RptInfo;
import com.zingrow.web.report.model.RptModuleInfo;
import com.zingrow.web.report.model.RptView;
import com.zingrow.web.report.response.ModuleData;
import com.zingrow.web.report.service.IDocExportor;
import com.zingrow.web.report.service.IRptDisplayService;
import com.zingrow.web.report.service.IRptEnshrineService;
import com.zingrow.web.report.service.IRptInfoService;
import com.zingrow.web.report.service.IRptModuleService;
import com.zingrow.web.report.service.IRptViewService;
import com.zingrow.web.report.service.impl.PdfDocExportor;
import com.zingrow.web.report.service.impl.WordDocExportor;
import com.zingrow.web.report.utils.DateUtils;
import com.zingrow.web.report.utils.RptJsonUtils;
import com.zingrow.web.support.operate.model.OptRecord;
import com.zingrow.web.support.operate.service.IOptRecordService;
import com.zingrow.web.user.model.ActiveUser;
import com.zingrow.web.user.model.User;
import com.zingrow.web.user.model.UserPermission;
import com.zingrow.web.user.service.IPermissionService;
import com.zingrow.web.user.service.IUserService;
import com.zingrow.web.base.enums.OperationModule;
import com.zingrow.web.base.enums.OperationMinModule;
import com.zingrow.web.base.enums.OperationDeed;

@Controller
@RequestMapping(value = "/rpt/display/", produces = "application/json;charset=UTF-8")
public class RptDisplayController extends BaseController {
	@Autowired
	IRptDisplayService rptDisplayService;
	@Autowired
	IRptInfoService rptInfoService;
	@Autowired
	IRptModuleService rptModuleService;
	@Autowired
	IRptViewService rptViewService;
	@Autowired
	IRptEnshrineService enshrineService;
	@Autowired
	private IOptRecordService ioptRecordService;
	@Autowired
	private IPermissionService permissionService;
	@Autowired
	private IOptRecordService optRecordService;
	@Autowired
	private IGroupService igroupService;
	@Autowired
	private IUserService iuserService;
	@Autowired
	private IRptInfoService irptInfoService;

	/**
     * 查询对应模版的信息数据
     */
    @ResponseBody
    @RequestMapping("selectModuleData")
    public String selectModuleData(HttpServletRequest httpRequest, HttpServletResponse response, Integer rptId,
            Integer moduleId, Integer userId, String operationId,String sp) {
        ModuleData moduleData = new ModuleData();
        // 查询出报告信息和模版相关的一些信息
        Integer cycleId=null;
        String rptName="";
        String minChannel=""; 
        //用户信息
        ActiveUser user = getUser(httpRequest);
        ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR, CodeMsg.MSG_ERROR,
                moduleData);
        String time = "yyyy-MM-dd HH:mm:ss";
        if (rptId == null || moduleId == null) {
            standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
            standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
            if(user.getUserType()==2){
            addOptRecode(httpRequest, optRecordService, OperationModule.report.toString(),
            		minChannel, "","rptId == null || moduleId == null");
            }
            return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
        }        
        try {  
        	if (sp != null || !"".equals(sp)) {
        		sp = EncodingUtils.fixUrlParamEncoding(httpRequest, sp);
			}
        	RptInfo rptInfo = rptInfoService.selectByRptInfoId(rptId);  
            if (rptInfo == null) {
                log.error("查询报告信息为空,ID:" + rptId);
              //异常记录
                if(user.getUserType()==2){
                addOptRecode(httpRequest, optRecordService, OperationModule.report.toString(),
                		minChannel, "异常","查询报告信息为空,ID:"+ rptId);
                }
                return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");            
            }
            else{
            	cycleId=rptInfo.getCycleId();
            	rptName=rptInfo.getName();
            }
            if(cycleId==1){
            	minChannel="日报";
            }
            if(cycleId==2){
            	minChannel="周报";
            }
            if(cycleId==3){
            	minChannel="月报";
            }    
            // 从模块记录表里查询出相应的方案信息
            RptModuleInfo module = rptModuleService.selectModuleInfo(rptInfo.getModelId(), moduleId);
            if (module == null) {
                log.error("查询模块信息为空,ID:" + moduleId);
              //异常记录
                if(user.getUserType()==2){
                addOptRecode(httpRequest, optRecordService, OperationModule.report.toString(),
                		minChannel, "异常","查询模块信息为空,ID:"+moduleId);
                }
                return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
            }
            // 查询出展示信息
            RptView view = rptViewService.selectRptView(module.getViewInfoId());
            if (view == null) {
                log.error("查询展示信息为空,ID:" + module.getViewInfoId());
                //异常记录
                if(user.getUserType()==2){
                addOptRecode(httpRequest, optRecordService, OperationModule.report.toString(),
                		minChannel, "异常","查询展示信息为空,ID:"+module.getViewInfoId());
                }
                return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
            }
            // 初始化返回数据
            moduleData = new ModuleData(moduleId, view.getName(), view.getTitle(), view.getViewText(),
                    view.getViewTypeId(), view.getExtraInfo(), view.getPointX(), view.getPointY());
            // 计算查询时间
            List<Date> dates = new ArrayList<>();
            if (Cycle.DAY.getCode().equals(rptInfo.getCycleId())) {// 日报
                dates.add(rptInfo.getStartTime());
            } else if (Cycle.WEEK.getCode().equals(rptInfo.getCycleId())) {// 周报(周日-周六)
                dates = DateUtils.getAllWeekDays(rptInfo.getStartTime());
            } else if (Cycle.MONTH.getCode().equals(rptInfo.getCycleId())) {// 月报（第一天-最后一天）
                dates = DateUtils.getAllMonthDays(rptInfo.getStartTime());
            } else {
                ;
            }
            // 从维度表中查询统计数据-并写入到返回数据中
            rptDisplayService.analyzeDisplayData(moduleData, module.getPlanItems(), rptInfo.getGroupName(), dates);
            if (moduleData.getTypeId() > 2) {
                time = "yyyy-MM-dd";
            }
            // 返回数据
            standardData.setReturnData(moduleData);
            standardData.setReturnCode(CodeMsg.CODE_OK);
            standardData.setReturnMessage(CodeMsg.MSG_OK);
        } catch (Exception e) {
            e.printStackTrace();
            standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
            standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
            log.error(e.getMessage());
        }
        
        //操作日志
        if(user.getUserType()==2){
        //判断参数
        if(StringUtils.isNotBlank(operationId)){	
        if(operationId.equals("4")){
        	//推送查看
        	addOptRecode(httpRequest, optRecordService, OperationModule.report.toString(),
            		minChannel, OperationDeed.pushCheck.toString() + "《" + rptName + "》","");
        }
        else if(operationId.equals("3")){
        	//历史查看
        	addOptRecode(httpRequest, optRecordService, OperationModule.me.toString(),
            		"历史", OperationDeed.checkHistory.toString() + "《" + rptName + "》","");
        }
        else if(operationId.equals("2")){
        	//收藏查看
        	addOptRecode(httpRequest, optRecordService, OperationModule.me.toString(),
            		"收藏", OperationDeed.checkCollection.toString() + "《" + rptName + "》","");
        }
        else if(operationId.equals("1")){
        	//自主查看
        	addOptRecode(httpRequest, optRecordService, OperationModule.report.toString(),
            		minChannel, OperationDeed.check.toString() + "《" + rptName + "》","");
                 }
             }
        }
        else
        {
        	if("0".equals(sp))
        	{
        	RptInfo skk=irptInfoService.selectByRptInfoId(rptId);	
        	ActiveUser opuser = getUser(httpRequest);//获取操作用户
			OptRecord s = new OptClass().reports_adds(opuser,Menu.Reportmanagement.toString(),
					Menu.Reportlist.toString(),Operation.youl.toString(),"预览所属组织("+skk.getGroupName()+")的报告("+skk.getName()+")");
			ioptRecordService.insert(s);	
			standardData.setReturnCode(CodeMsg.CODE_OK);
			standardData.setReturnMessage(CodeMsg.MSG_OK);
        	}
        }
        return RptJsonUtils.toString(standardData, time);
               
    }

	/**
	 * 导出Wrod报告
	 */
	@ResponseBody
	@RequestMapping(value = "exportWord", method = RequestMethod.POST)
	public String exportWord(HttpServletRequest request, HttpServletResponse response, String id, String svg) {
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR, CodeMsg.MSG_ERROR,
				null);
		if (!StringUtils.isNumeric(id)) {
			standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
			standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
			return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
		}
		ObjectMapper objMap = new ObjectMapper();
		// 报告ID
		Integer rptId = Integer.valueOf(id);
		// 文件名称
		String rptTitle = "";
		List<ModuleData> moduleDatas = new ArrayList<>();
		// 一些数据信息
		Map<String, String> infos = new HashMap<>();
		OutputStream out = null;
		try {
			@SuppressWarnings("unchecked")
			Map<String, String> svgs = objMap.readValue(svg, Map.class);
			// 查询出报告信息和模版相关的一些信息
			RptInfo rptInfo = rptInfoService.selectByRptInfoId(rptId);
			if (rptInfo == null || StringUtils.isBlank(rptInfo.getModuleSort())) {
				log.error("查询报告信息为空,ID:" + rptId);
				return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			rptTitle = rptInfo.getGroupName() + "-" + rptInfo.getName();
			// 根据模块id逐个查询数据
			String[] modules = rptInfo.getModuleSort().split(",");
			infos.put(IDocExportor.GAROUP_NAME, rptInfo.getGroupName());
			infos.put(IDocExportor.RPT_NAME, rptInfo.getName());
			for (String moduleIdStr : modules) {
				if (StringUtils.isNumeric(moduleIdStr)) {
					Integer moduleId = Integer.valueOf(moduleIdStr);
					// 从模块记录表里查询出相应的方案信息
					RptModuleInfo module = rptModuleService.selectModuleInfo(rptInfo.getModelId(), moduleId);
					if (module == null) {
						continue;
					}
					// 查询出展示信息
					RptView view = rptViewService.selectRptView(module.getViewInfoId());
					if (view == null) {
						continue;
					}
					ModuleData moduleData = new ModuleData(moduleId, view.getName(), view.getTitle(),
							view.getViewText(), view.getViewTypeId(), view.getExtraInfo(), view.getPointX(),
							view.getPointY());
					// 计算查询时间
					List<Date> dates = new ArrayList<>();
					if (Cycle.DAY.getCode().equals(rptInfo.getCycleId())) {// 日报
						dates.add(rptInfo.getStartTime());
					} else if (Cycle.WEEK.getCode().equals(rptInfo.getCycleId())) {// 周报(周日-周六)
						dates = DateUtils.getAllWeekDays(rptInfo.getStartTime());
					} else if (Cycle.MONTH.getCode().equals(rptInfo.getCycleId())) {// 月报（第一天-最后一天）
						dates = DateUtils.getAllMonthDays(rptInfo.getStartTime());
					} else {
						;
					}
					try {
						// 从维度表中查询统计数据-并写入到返回数据中
						rptDisplayService.analyzeDisplayData(moduleData, module.getPlanItems(), rptInfo.getGroupName(),
								dates);
					} catch (Exception e) {
						continue;
					}
					moduleDatas.add(moduleData);
				}
			}
			out = response.getOutputStream();
			response.reset();// 清空输出流
			response.setHeader("Content-disposition",
					"attachment; filename=" + new String(rptTitle.getBytes("gb2312"), "ISO8859-1") + ".doc");// 设定输出文件头
			response.setContentType("application/msword");// 定义输出类型
			new WordDocExportor().createDoc(infos, moduleDatas, svgs, out).writeToStream();

			RptInfo skk = irptInfoService.selectByRptInfoId(rptId);
			ActiveUser opuser = getUser(request);// 获取操作用户
			OptRecord s = new OptClass().reports_adds(opuser, Menu.Reportmanagement.toString(),
					Menu.Reportlist.toString(), Operation.daochu.toString(),
					"Wrod导出所属组织(" + skk.getGroupName() + ")的报告(" + skk.getName() + ")");
			ioptRecordService.insert(s);
			standardData.setReturnCode(CodeMsg.CODE_OK);
			standardData.setReturnMessage(CodeMsg.MSG_OK);

		} catch (Exception e) {
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			log.error(e.getMessage());
			return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
		}
		return null;
	}

	/**
	 * 导出PDF报告
	 */
	@ResponseBody
	@RequestMapping(value = "exportPdf", method = RequestMethod.POST)
	public String exportPdf(HttpServletRequest request, HttpServletResponse response, String id, String svg) {
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR, CodeMsg.MSG_ERROR,
				null);
		if (!StringUtils.isNumeric(id)) {
			standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
			standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
			return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
		}
		ObjectMapper objMap = new ObjectMapper();
		// 报告ID
		Integer rptId = Integer.valueOf(id);
		// 文件名称
		String rptTitle = "";
		List<ModuleData> moduleDatas = new ArrayList<>();
		// 一些数据信息
		Map<String, String> infos = new HashMap<>();
		OutputStream out = null;
		try {
			@SuppressWarnings("unchecked")
			Map<String, String> svgs = objMap.readValue(svg, Map.class);
			// 查询出报告信息和模版相关的一些信息
			RptInfo rptInfo = rptInfoService.selectByRptInfoId(rptId);
			if (rptInfo == null || StringUtils.isBlank(rptInfo.getModuleSort())) {
				log.error("查询报告信息为空,ID:" + rptId);
				return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			rptTitle = rptInfo.getGroupName() + "-" + rptInfo.getName();
			// 根据模块id逐个查询数据
			String[] modules = rptInfo.getModuleSort().split(",");
			infos.put(IDocExportor.GAROUP_NAME, rptInfo.getGroupName());
			infos.put(IDocExportor.RPT_NAME, rptInfo.getName());
			for (String moduleIdStr : modules) {
				if (StringUtils.isNumeric(moduleIdStr)) {
					Integer moduleId = Integer.valueOf(moduleIdStr);
					// 从模块记录表里查询出相应的方案信息
					RptModuleInfo module = rptModuleService.selectModuleInfo(rptInfo.getModelId(), moduleId);
					if (module == null) {
						continue;
					}
					// 查询出展示信息
					RptView view = rptViewService.selectRptView(module.getViewInfoId());
					if (view == null) {
						continue;
					}
					ModuleData moduleData = new ModuleData(moduleId, view.getName(), view.getTitle(),
							view.getViewText(), view.getViewTypeId(), view.getExtraInfo(), view.getPointX(),
							view.getPointY());
					// 计算查询时间
					List<Date> dates = new ArrayList<>();
					if (Cycle.DAY.getCode().equals(rptInfo.getCycleId())) {// 日报
						dates.add(rptInfo.getStartTime());
					} else if (Cycle.WEEK.getCode().equals(rptInfo.getCycleId())) {// 周报(周日-周六)
						dates = DateUtils.getAllWeekDays(rptInfo.getStartTime());
					} else if (Cycle.MONTH.getCode().equals(rptInfo.getCycleId())) {// 月报（第一天-最后一天）
						dates = DateUtils.getAllMonthDays(rptInfo.getStartTime());
					} else {
						;
					}
					try {
						// 从维度表中查询统计数据-并写入到返回数据中
						rptDisplayService.analyzeDisplayData(moduleData, module.getPlanItems(), rptInfo.getGroupName(),
								dates);
					} catch (Exception e) {
						e.printStackTrace();
						continue;
					}
					moduleDatas.add(moduleData);
				}
			}
			out = response.getOutputStream();
			response.reset();// 清空输出流
			response.setHeader("Content-disposition",
					"attachment; filename=" + new String(rptTitle.getBytes("gb2312"), "ISO8859-1") + ".pdf");// 设定输出文件头
			response.setContentType("application/octet-stream; charset=UTF-8");// 定义输出类型
			new PdfDocExportor().createDoc(infos, moduleDatas, svgs, out).writeToStream();
			RptInfo skk = irptInfoService.selectByRptInfoId(rptId);
			ActiveUser opuser = getUser(request);// 获取操作用户
			OptRecord s = new OptClass().reports_adds(opuser, Menu.Reportmanagement.toString(),
					Menu.Reportlist.toString(), Operation.daochu.toString(),
					"PDF导出所属组织(" + skk.getGroupName() + ")的报告(" + skk.getName() + ")");
			ioptRecordService.insert(s);
		} catch (Exception e) {
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			log.error(e.getMessage());
			e.printStackTrace();
			return RptJsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
		}
		return null;
	}

	/**
	 * 查询报告列表信息
	 */
	@ResponseBody
	@RequestMapping("selectRptInfo")
	public String selectRptInfo(HttpServletRequest request, HttpServletResponse response, Integer pageIndex,
			Integer pageSize, RptInfo rptInfo, Integer userId,
			@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date releaseTime1,
			@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date releaseTime2) {
		List<RptInfo> list = new ArrayList<>();
		PageView pageView = null;
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR, CodeMsg.MSG_ERROR,
				list);
		// ActiveUser user = getUser(request);
		try {

			// 设置分页
			if (pageIndex == null || pageIndex <= 0) {
				pageIndex = 1;
			}
			if (pageSize == null || pageSize <= 0) {
				pageSize = 10;
			}
			pageView = new PageView(pageSize, pageIndex);
			// 字符转换
			if (StringUtils.isNoneBlank(rptInfo.getName())) {
				rptInfo.setName(EncodingUtils.fixUrlParamEncoding(request, rptInfo.getName()).replace("%", "\\%"));
			}
			list = rptInfoService.selectAll(pageView, rptInfo.getName(), rptInfo.getGroupId(), rptInfo.getCycleId(),
					userId, releaseTime1, releaseTime2);
			String groupname = igroupService.selectGroupNameByGroupid(rptInfo.getGroupId());
			String useraccount = null;
			if (userId != null)
				useraccount = iuserService.querybyuserid(userId).getUserAccount();
			// 新增一条操作记录
			ActiveUser opuser = getUser(request);// 获取操作用户
			OptRecord s = new OptClass().reports_query(opuser, Menu.Reportmanagement.toString(),
					Menu.Reportlist.toString(), Operation.query.toString(), rptInfo.getName(), groupname,
					rptInfo.getCycleId(), useraccount, releaseTime1, releaseTime2);
			if (!s.getOptName().equals("null"))
				ioptRecordService.insert(s);
			standardData.setReturnData(list);
			standardData.setReturnCode(CodeMsg.CODE_OK);
			standardData.setReturnMessage(CodeMsg.MSG_OK);
			standardData.setTotalPages(pageView.getPageCount());
			standardData.setTotalRecords(pageView.getRowCount());
		} catch (Exception e) {
			log.error("根据参数查询异常");
			ActiveUser opuser = getUser(request);// 获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser, "报告管理报告列表查询异常");
			ioptRecordService.insert(s);
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			standardData.setReturnData(list);
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}

	@RequestMapping("delete")
	@ResponseBody
	public String delete(HttpServletRequest request, HttpServletResponse response, Integer id, String name,
			String groupName) {
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR, CodeMsg.MSG_ERROR,
				null);
		try {
			if (name != null || !"".equals(name)) {
				name = EncodingUtils.fixUrlParamEncoding(request, name);
			}
			if (groupName != null || !"".equals(groupName)) {
				groupName = EncodingUtils.fixUrlParamEncoding(request, groupName);
			}
			if (id == null) {
				standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			if (rptInfoService.delete(id)) {
				ActiveUser opuser = getUser(request);// 获取操作用户
				OptRecord s = new OptClass().reports_delete(opuser, Menu.Reportmanagement.toString(),
						Menu.Reportlist.toString(), Operation.delete.toString(), name, groupName);
				ioptRecordService.insert(s);
				standardData.setReturnCode(CodeMsg.CODE_OK);
				standardData.setReturnMessage(CodeMsg.MSG_OK);
			} else {
				ActiveUser opuser = getUser(request);// 获取操作用户
				OptRecord s = new OptClass().recordabnormality(opuser, "报告列表删除失败");
				ioptRecordService.insert(s);
				standardData.setReturnCode(CodeMsg.CODE_ERROR);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR);
			}
		} catch (Exception e) {
			log.error("删除异常");
			ActiveUser opuser = getUser(request);// 获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser, "报告列表删除异常");
			ioptRecordService.insert(s);
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 手机APP 查询报告列表接口
	 */
	@ResponseBody
	@RequestMapping("selectAllByIduserId")
	public String selectAllByIduserId(HttpServletRequest request, HttpServletResponse response, Integer pageIndex,
			RptInfo rptInfo, Integer pageSize, Integer userId,
			@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date releaseTime1,
			@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date releaseTime2) {
		List<RptInfo> list = new ArrayList<>();
		PageView pageView = null;
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR, CodeMsg.MSG_ERROR,
				list);
		try {
			// 设置分页
			if (pageIndex == null || pageIndex <= 0) {
				pageIndex = 1;
			}
			if (pageSize == null || pageSize <= 0) {
				pageSize = 10;
			}
			pageView = new PageView(pageSize, pageIndex);
			list = rptInfoService.selectAllByIduserId(pageView, rptInfo.getName(), rptInfo.getGroupId(),
					rptInfo.getCycleId(), userId, releaseTime1, releaseTime2);
			standardData.setReturnData(list);
			standardData.setReturnCode(CodeMsg.CODE_OK);
			standardData.setReturnMessage(CodeMsg.MSG_OK);
			standardData.setTotalPages(pageView.getPageCount());
			standardData.setTotalRecords(pageView.getRowCount());
		} catch (Exception e) {
			log.error("根据参数查询异常");
			log.error(e.getMessage());
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			standardData.setReturnData(list);
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
}
